home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 May: Tool Chest / Developer CD Series Tool Chest (Apple Computer)(May 1999).iso / Tool Chest / Memory / DIMM Config&Interleave v1.1 / Interleave.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-13  |  8.0 KB  |  257 lines  |  [TEXT/CWIE]

  1. //==============================================================
  2. // Memory Interleave Tester:
  3. //    7/25/97
  4. //
  5. //    Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  6. //
  7. //    You may incorporate this sample code into your applications without
  8. //    restriction, though the sample code has been provided "AS IS" and the
  9. //    responsibility for its operation is 100% yours.  However, what you are
  10. //    not permitted to do is to redistribute the source as "DSC Sample Code"
  11. //    after having made changes. If you're going to re-distribute the source,
  12. //    we require that you make it clear in the source that the code was
  13. //    descended from Apple Sample Code, but that you've made changes.
  14. //
  15. //    Change History:
  16. //        • Formerly, we were using Gestalt to see if we should run, and hard
  17. //        coded the machines that it worked on.  Now, just use the FindHammerHead
  18. //        function, and if it works, use it, else bail out.
  19. //        • Also still hard code to given machines, in order to print out the list of
  20. //        installed ram, and give the physical locations of the DIMM slots.
  21. //
  22. //==============================================================
  23. // This is a test application to demonstrate how to call the TestBanks
  24. //    routine, in order to determine if the RAM installed in the computer
  25. //    is being used in an interleaved fashion or not.  Interleaved memory
  26. //    is substantially faster, up to twice as fast as non-interleaved.
  27. //
  28. // The program needs to figure out which machine it is on specifically, so that
  29. //    it can make a mapping between physical DIMM slots, and what the Hammerhead
  30. //    registers come back with.  Naturally this couldn't be a simple one to one mapping,
  31. //    these are computers. 
  32. //    So, there are machine specific print out routines, which take the array data and
  33. //    turn it into a form that makes sense.  If we don't have a specific machine match,
  34. //    then we do a generic version, so that you can see what it looks like, even though
  35. //    we cannot give you the physical mapping.  
  36. //
  37. // Quick, dirty, and comes with no warranty.  This will only work on 
  38. //    PowerMac's that support a version of the HammerHead memory controller. 
  39. //    Nothing else is allowed to run.  Since we look at the hardware directly,
  40. //     naturally it's machine dependent. 
  41. //
  42. //    However, if you have any trouble with it, please contact Apple's DTS,
  43. //     at <devsupport@apple.com>
  44. //
  45. //    Peter Baum, Bo3b Johnson, and Quinn.
  46.  
  47. #include <gestalt.h>
  48. #include <stdio.h>
  49. #include <Types.h>
  50.  
  51. #include "Interleave.h"
  52.  
  53.  
  54. //==============================================================
  55. // Print a given Bank's information.  Just a common routine, for display.
  56.  
  57. static void
  58. PrintBankInfo(short    k, RAMBankDescriptorPtr theBanks)
  59. {
  60.     printf ("%3.0d/%3.0d ", theBanks[k].bankSize, theBanks[k+1].bankSize);
  61.  
  62.     if (theBanks[k].bankIsInterleaved)
  63.         printf ("Interleaved");
  64.     else
  65.         printf(" --- ");
  66.  
  67.     printf("\n");
  68. }
  69.  
  70.  
  71. //==============================================================
  72. // The loop counters go by funny numbers in order to display the banks
  73. //     in a reasonable order. (ie. A1/B1 front, A1/B1 back.)
  74. //    This maps the memory installed into the physical slot numbers that
  75. //    are silk screened onto the motherboard. Front & Back don't really mean
  76. //    that...they are just nomenclature for two banks per DIMM.
  77. //
  78. //    The first two banks, 0, and 1, are skipped, because they are for the 
  79. //    MotherBoard banks, which don't exist on these computers.
  80.     
  81. static void
  82. Print75008500 (RAMBankDescriptorPtr  theBanks)
  83. {
  84.     short                 i;
  85.     short                 j;
  86.     OSErr                err;
  87.  
  88.     printf ("Motherboard Row-> not implemented\n");    
  89.  
  90.     for (i=1; i<=4; i++)    
  91.     {
  92.         printf ("A%d/B%d (row 0) -> ", i, i);    
  93.         j = 18-(4*i);
  94.         PrintBankInfo(j, theBanks);
  95.     
  96.         printf ("A%d/B%d (row 1) -> ", i, i);    
  97.         j = 20-(4*i);
  98.         PrintBankInfo(j, theBanks);
  99.     }
  100. }
  101.  
  102.  
  103. //==============================================================
  104. //    The first two banks, 0, and 1, are skipped, because they are for the 
  105. //    MotherBoard banks, which don't exist on these computers.
  106.  
  107. static void 
  108. Print9500 (RAMBankDescriptorPtr  theBanks)
  109. {
  110.     short                 i;
  111.     short                 j;
  112.     OSErr                err;
  113.  
  114.     printf ("Motherboard Row-> not implemented\n");    
  115.  
  116.     // Decipher the bank information, and display it.
  117.     for (i=1; i<=6; i++)        
  118.     {
  119.         printf ("A%d/B%d (row 0) -> ", i, i);    
  120.         j = (4*i)-2;
  121.         PrintBankInfo(j, theBanks);
  122.         
  123.         printf ("A%d/B%d (row 1) -> ", i, i);    
  124.         j = 4*i;
  125.         PrintBankInfo(j, theBanks);
  126.     }
  127. }        
  128.  
  129. //==============================================================
  130. // If we don't know which machine we are on, but we got the BankInfo, then
  131. //    we have a new machine we don't know about.  Dump out the memory in a 
  132. //    generic form, so they can see what's in the HammerHead registers.
  133.  
  134. static void 
  135. PrintGenericMac (RAMBankDescriptorPtr  theBanks)
  136. {
  137.     short                 i;
  138.     short                 j;
  139.     OSErr                err;
  140.  
  141.     // Since PrintBankInfo just prints two slots at a time, just increment through them.
  142.     for (i = 0; i < 13; i++)        
  143.     {
  144.         printf ("x%d/x%d         -> ", i, i);    
  145.         j = 2 * i;
  146.         PrintBankInfo(j, theBanks);
  147.     }
  148. }        
  149.  
  150. //==============================================================
  151. // Get physical memory in Megabytes.
  152.  
  153. static UInt32    
  154. GetPhysicalMemSize()
  155. {
  156.     long    myAttr;
  157.     long    theSize;
  158.     OSErr    err;
  159.     
  160.     err = Gestalt( gestaltPhysicalRAMSize, &myAttr);
  161.      if (err == noErr) 
  162.          theSize = myAttr / (1024*1024);
  163.      else
  164.          theSize = 0;
  165.      
  166.      return(theSize);
  167. }
  168.  
  169.  
  170. //==============================================================
  171. void
  172. main() 
  173. {
  174.     OSErr                    err;
  175.     long                    machineAttribute;
  176.     Ptr                        hammerHeadAddress;
  177.     long                    theRAMSize;
  178.     RAMBankDescriptor        allBanks[26];
  179.     
  180.     
  181.     printf ("Welcome to the Display DIMM Configuration\n\n");
  182.     printf ("A Primer on DIMMs:\n");
  183.     printf ("Each DIMM in the 7500/8500/9500 can support two 'rows' of memory.\n");
  184.     printf ("You can't tell by looking at the RAM (i.e. it doesn't matter if it's \n");
  185.     printf ("got RAM on both sides of DIMM.) Most DIMMs have only a single row.\n");
  186.     printf ("The 7500/8500 has 8 DIMM slots labelled A1 thru A4 and B1 thru B4.\n");
  187.     printf ("The   9500   has 12 DIMM slots labelled A1 thru A6 and B1 thru B6.\n\n");
  188.     printf ("To interleave memory, the DIMM in slot Ax must match the DIMM in Bx.\n");
  189.     printf ("In the list below, each line represents a pair of slots which can \n");
  190.     printf ("be interleaved. If the pair of DIMMs is interleaved properly \n"); 
  191.     printf ("the word 'Interleaved' will appear at the end of the line. \n\n");
  192.     printf ("by Peter Baum, Bo3b Johnson, Quinn - v1.1    © 1996 Apple Computer, Inc. \n\n\n");
  193.  
  194.     // FindHammerHead is a well behaved routine, and so we can just call it without
  195.     //    worrying about computer and so on.  If this machine has a HammerHead, we
  196.     //    get noErr, and the result.  Otherwise, we don't support the current machine.
  197.     err = FindHammerHead(&hammerHeadAddress);
  198.  
  199.     if (err != noErr) {
  200.         printf("---Unsupported Macintosh---");
  201.         return;                                    // waits for them to Command-Q to leave.
  202.     }
  203.         
  204.  
  205.     // Start the display with the total memory in the machine.
  206.     theRAMSize = GetPhysicalMemSize();
  207.     if (theRAMSize == 0) {
  208.         printf ("---Error getting memory size---\n");
  209.         return;
  210.     }
  211.     else {
  212.         printf ("Total Memory = %d Megs in \n", theRAMSize);
  213.     }
  214.     
  215.     
  216.     // Ask the routine to fetch the RAM Bank info.  Fill out the descriptors.
  217.     err = GetPhysicalRAMBankInfo(allBanks, theRAMSize, hammerHeadAddress);
  218.     if (err != noErr) {
  219.         printf ("---Couldn't get info on the banks---\n");
  220.         return;
  221.     }
  222.     
  223.     // Decide what machine we are on, and display the RAM banks data that
  224.     //    currently is installed.
  225.      err = Gestalt(gestaltMachineType, &machineAttribute);
  226.      switch (machineAttribute)
  227.     {
  228.         case gestaltPowerMac7500:    
  229.             printf ("7500 DIMM Slots: Meg/Meg 'Interleaved'\n");
  230.             printf ("                 ---/--- \n");
  231.             Print75008500(allBanks);
  232.             break;
  233.             
  234.         case gestaltPowerMac8500:
  235.             printf ("8500 DIMM Slots: Meg/Meg 'Interleaved'\n");
  236.             printf ("                 ---/--- \n");
  237.             Print75008500(allBanks);
  238.             break;
  239.             
  240.         case gestaltPowerMac9500:    
  241.             printf ("9500 DIMM Slots: Meg/Meg 'Interleaved'\n");
  242.             printf ("                 ---/--- \n");
  243.             Print9500(allBanks);
  244.             break;
  245.     
  246.         default: 
  247.             printf ("Unknown PowerMac: Meg/Meg 'Interleaved'\n");
  248.             printf ("                 ---/--- \n");
  249.             PrintGenericMac(allBanks);
  250.             break;
  251.     }
  252.  }
  253.  
  254.  
  255.  
  256.  
  257.